/****** Object:  Stored Procedure [dbo].spChiTietPhieuNhapSelectAllByMaThuoc Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[spChiTietPhieuNhapSelectAllByMaThuoc]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spChiTietPhieuNhapSelectAllByMaThuoc]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		14/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[spChiTietPhieuNhapSelectAllByMaThuoc]
(
	@MaThuoc nvarchar(12),
	@MaKho nvarchar(6),
	@StoreMoreThan int
)
WITH ENCRYPTION

AS

SET NOCOUNT ON
SELECT
	tbl_LuuKho.*,
	tbl_ChiTietPhieuNhap.SoPN,
	tbl_ChiTietPhieuNhap.SoLuong,
	tbl_ChiTietPhieuNhap.DonGia
FROM tbl_LuuKho INNER JOIN tbl_ChiTietPhieuNhap ON tbl_ChiTietPhieuNhap.MaLUuKho = tbl_LuuKho.MaLuuKho
WHERE [MaThuoc] = @MaThuoc 
AND ((@MaKho is null) or (MaKho = @Makho))
AND ((@StoreMoreThan is null) or (@StoreMoreThan<TonKho))
GO

--GRANT EXECUTE ON [dbo].[spChiTietPhieuNhapSelectAllByMaThuoc] TO [sa]
--GO
